package com.boyan.order.controller;


import com.boyan.order.bean.Order;
import com.boyan.order.properties.OrderProperties;
import com.boyan.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//自动刷新注解
//@RefreshScope
//@RequestMapping("/api/order")
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private OrderService orderService;

    @Autowired
    OrderProperties orderProperties;


    @GetMapping("/config")
    public String config(){
        return "order.timeout:"+orderProperties.getTimeout()+",order.auto-confirm:"+orderProperties.getAutoConfirm()
                +",order.db-url:"+orderProperties.getDbUrl();
    }

    @GetMapping("/create")
    public Order createOrder(@RequestParam("userId") Long userId,
                             @RequestParam("productId") Long productId) {
        return orderService.createOrder(productId, userId);
    }

    @GetMapping("/readDb")
    public String readDb(){
        log.info("readDb...");
        return "readDb success";
    }




}
